﻿{include file="public/header"}
<title>订单录入</title>
</head>
<body>
<style>
    .col-sm-1 {
        width: 20.333333%;
        text-align: center;
    }
</style>

<article class="page-container">
    <form>
        <div class="ch-row ch-info-form">
            <div class="flex1">序号：</div>
            <div class="flex2">
                <input type="text" name="serial" class="form-control title" placeholder="请输入序号">
                <input type="hidden" name="detaileds_id" value="{$data}">
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <div class="flex1">施工项目：</div>
            <div class="flex2">
                <input type="text" name="detailed_title" class="form-control title" placeholder="请输入施工项目">
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <div class="flex1">单位：</div>
            <div class="flex2">
                <select name="un_id" class="form-control">
                    <option selected="selected" value="">请选择</option>
                    {volist name='g' id='v'}
                    <option value="{$v.id}">{$v.title}</option>
                    {/volist}
                </select>
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <div class="flex1">人工费：</div>
            <div class="flex2">
                <input type="text" name="artificial" class="form-control title" placeholder="请输入人工费">
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <div class="flex1">备注：</div>
            <div class="flex2">
                <textarea class="form-control" placeholder="请输入备注" name="rmakes"></textarea>
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <div class="flex1">人工结算价：</div>
            <div class="flex2">
                <input type="text" class="form-control" name="pri" placeholder="人工结算价">
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <div class="flex1">结算备注：</div>
            <div class="flex2">
                <textarea class="form-control" placeholder="请输入结算备注" name="pris"></textarea>
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <div class="flex1">排序：</div>
            <div class="flex2">
                <input type="text" class="form-control" name="xu">
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <div class="flex1">关联供应商：</div>
            <div class="flex2">
                <div><input type="text" class="form-control " id="xu" name="xu" style="width: 50%;
    display: inline-block;">
                    <button class="btn btn-primary dian" style="width:27%;    margin-top: 0px;" type="button"><i
                            class="Hui-iconfont">&#xe632;</i> 提交
                    </button>
                </div>

            </div>
        </div>
        <div class="ch-row ch-info-form">

            <div id="lie" style="margin-left: 34%;">
            </div>


        </div>

        <div class="ch-row">
            <div class="flex1">
                <button class="btn btn-primary radius" style="width: 100%;" type="button"><i class="Hui-iconfont">&#xe632;</i>
                    提交
                </button>
            </div>
        </div>
    </form>
</article>
{include file="public/footer"}
<script>
    $('.radius').click(function () {
        var src = "{:Url('index/Detailed/add')}?id=0";
        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        $.ajax({
            type: 'POST',
            url: src,
            dataType: 'json',
            data: $('form').serializeArray(),
            success: function (data) {
                var res = JSON.parse(data);
                if (res.code == 200) {

                    window.parent.location.reload(); //刷新父页面
                    parent.layer.close(index);  // 关闭layer

                } else {
                    layer.msg(res.msg, {icon: 5, time: 1000});
                }

            },
            error: function (data) {
                console.log(data.msg);
            },
        });
    });
    $('.dian').click(function () {
        var src = "{:Url('index/Detailed/agency')}";
        var index = $("#xu").val();
        var html = '';
        $.ajax({
            type: 'POST',
            url: src,
            dataType: 'json',
            data: {name: index},
            success: function (data) {
                var res = JSON.parse(data);
                if (res.code == 200) {

                    if (res.data.length > 0) {

                        for (var i = 0; i < res.data.length; i++) {
                            var index = $("#id_" + res.data[i]['agency_id']).val();
                            if (index != res.data[i]['agency_id']) {
                                html += " <div class='flex2 guan' ><span>" + res.data[i]['random_number'] + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + res.data[i]['agency_name'] + "</span><input type='hidden' name='agency_id[]' id='id_" + res.data[i]['agency_id'] + "' value='" + res.data[i]['agency_id'] + "'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a>删除</a></div>";
                            }

                        }
                    } else {
                        alert('供应商编号错误或无此供应商')
                    }

                    $('#lie').append(html);
                } else {
                    console.log(res.msg);
                }

            },

        });

    });

    $("#lie").on("click", ".guan", function () {
        var thit = this;
        layer.confirm('确认要删除吗？', {
            btn: ['确定', '取消']//按钮
        }, function (index) {
            layer.close(index);
            $(thit).remove();
            //此处请求后台程序，下方是成功后的前台处理……


        });


    });
</script>
</body>
</html>